package com.qtyx.nms.ui.adapter

import android.content.Context
import android.graphics.Color
import android.widget.LinearLayout
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.ldd.base.ui.adapter.BaseRVAdapter
import com.ldd.base.ui.adapter.BaseRVVH
import com.qtyx.nms.R
import com.qtyx.nms.mvp.model.bean.NurseBean
import com.qtyx.nms.ui.activity.HomePageActivity
import com.qtyx.nms.util.DisplayUtil


/**
 * 床位适配器
 */
class BedAdapter(mContext: Context, list: List<NurseBean.Data.SqlData>) :BaseRVAdapter<NurseBean.Data.SqlData>(mContext, list) {
    override fun getLayoutId(viewType: Int)= R.layout.item_bed
    var selectPosition=-1
    private val margin10=DisplayUtil.dp2px(13f)
    var contentColor=""

    override fun convert(vh: BaseRVVH, position: Int, data: NurseBean.Data.SqlData) {
        val tvBedNum=vh.getView<TextView>(R.id.tv_item_bed_num)

        val tvBedNumParams=tvBedNum.layoutParams as LinearLayout.LayoutParams
        //第一排顶距处理
        if(position<11){
            tvBedNumParams.topMargin=0
            tvBedNumParams.leftMargin=margin10
        }else{
            tvBedNumParams.topMargin=margin10
            tvBedNumParams.leftMargin=margin10
        }

        if(selectPosition==position){
            tvBedNum.setBackgroundResource(R.drawable.shape_item_nurse_bed_select_bg)
        }else{
            tvBedNum.setBackgroundResource(R.drawable.shape_item_nurse_bed_bg)
        }

        tvBedNum.setOnClickListener{
            selectPosition=position
            notifyDataSetChanged()
        }
        tvBedNum.text=data.BED_NO+"床"
        if(contentColor.isNotEmpty()){
            tvBedNum.setTextColor(Color.parseColor(contentColor))
        }
    }

}